package com.thrc.borrow.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.alibaba.fastjson.JSONObject;
import com.thrc.borrow.entity.OfflineApply;
import com.thrc.borrow.service.OfflineApplyService;
import com.thrc.borrow.utils.ResponseUtil;
import com.thrc.borrow.utils.ReturnCode;
import com.thrc.borrow.vo.OfflineApplyVo;

/**
 * 企业相关
 * 
 * @author suker.zhou
 *
 */
@Controller
@RequestMapping("/offline/apply")
public class OfflineApplyController {

	@Autowired
	private OfflineApplyService offlineService;

	@RequestMapping("/list/page")
	public String goUserJsp() {

		return "sys/offlineApplyList";
	}

	@RequestMapping("/getById")
	public void selectById(HttpServletResponse response, OfflineApply t) {
		OfflineApplyVo vo = offlineService.selectById(t);
		ResponseUtil.print(response, vo);
	}

	@RequestMapping("/selectAll")
	public void selectAll(HttpServletResponse response, OfflineApply t) {
		try {
			List<OfflineApplyVo> UserList = offlineService.selectAll(t);
			ResponseUtil.print(response, UserList);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseUtil.print(response, ReturnCode.FAIL_CODE, e.getMessage());
		}
	}

	@RequestMapping("/selectByPage")
	public void selectByPage(HttpServletResponse response, OfflineApply t) {

		JSONObject retJson = new JSONObject();
		try {
			int totleCount = offlineService.selectCount(t);
			retJson.put("total", totleCount);
			if (totleCount == 0) {
				retJson.put("data", null);
				ResponseUtil.print(response, retJson);
				return;
			}
			List<OfflineApplyVo> UserList = offlineService.selectByPage(t);
			retJson.put("data", UserList);
			ResponseUtil.print(response, retJson);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseUtil.print(response, ReturnCode.FAIL_CODE, e.getMessage());
		}
	}

	@RequestMapping("/insert")
	public void insert(HttpServletResponse response, HttpServletRequest request, OfflineApply t) {

		try {
			t.setCreate_time(new Date());
			offlineService.insert(t);
			ResponseUtil.print(response, ReturnCode.SUCCESS_CODE);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseUtil.print(response, ReturnCode.FAIL_CODE, e.getMessage());
		}
	}

	@RequestMapping("/update")
	public void update(HttpServletResponse response, OfflineApply t) {
		try {
			offlineService.update(t);
			ResponseUtil.print(response, ReturnCode.SUCCESS_CODE);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseUtil.print(response, ReturnCode.FAIL_CODE, e.getMessage());
		}
	}

	@RequestMapping("/delete")
	public void delete(HttpServletResponse response, OfflineApply t) {

		try {
			offlineService.delete(t);
			ResponseUtil.print(response, ReturnCode.SUCCESS_CODE);
		} catch (Exception e) {
			e.printStackTrace();
			ResponseUtil.print(response, ReturnCode.FAIL_CODE, e.getMessage());
		}
	}

}
